package org.example.login.Proxy;


import com.alibaba.fastjson.JSONObject;
import org.example.feign.pojo.Customer;
import org.example.feign.pojo.JsCode2SessionResponse;
import org.example.feign.pojo.JsCodeRequest;
import org.example.login.service.JsCode2SessionService;
import org.example.login.service.UitlsService;
import org.example.login.service.WxSessionService;

import java.io.IOException;

public class JsCode2SessionServiceProxy implements JsCode2SessionService {


    private final UitlsService UitlsService;
    private final WxSessionService WxSessionService;

    private  int id;
    public JsCode2SessionServiceProxy(UitlsService uitlsService, WxSessionService wxSessionService) {
        this.UitlsService = uitlsService;
        this.WxSessionService = wxSessionService;
    }

    @Override
    public JsCode2SessionResponse getJsCode2Session(JsCodeRequest request) throws IOException {
        // 获取用户信息
        Customer customer = WxSessionService.inCustomer(request.getUserInfo(), request.getCode(), request.getUserInfo1());

        JSONObject jsonObject = UitlsService.getWxOpenid(request.getCode());

        String openid = jsonObject.getString("openid");

        // 更新Customer对象的openid

        // 返回JsCode2SessionResponse对象
        return WxSessionService.ReturnJsResponse(openid,
                WxSessionService.Updata(customer, openid,
                        WxSessionService.getID(request.getUserInfo(), request.getUserInfo1())),
                jsonObject);
    }
}